import React, { Component } from 'react';
import {
  Dimensions,
  Platform,
  NativeModules,
  DeviceInfo,
  StyleSheet,
  Image,
  Text,
  View,
  TextInput,
  PixelRatio,
  TouchableOpacity
} from 'react-native';
var Common = require('./common');
// iPhoneX
const X_WIDTH = 375;
const X_HEIGHT = 812;

// screen
const SCREEN_WIDTH = Dimensions.get('window').width;
const SCREEN_HEIGHT = Dimensions.get('window').height;

const pixelRatio = PixelRatio.get();
const dismissKeyboard = require('dismissKeyboard');
export default class SendVideo extends Component<Props> {
  constructor(props){
    super(props);
    this.state = {
      iphonex:false,
      showCeng:false,
      str: '推荐',
      news:[{"title":"ssss"},{"title":"ssss"},],
      imgsrc:'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1514356844477&di=7c57fde0860194258cbec5c2720e0cf5&imgtype=0&src=http%3A%2F%2Fwww.swkweike.com%2Fdata%2Fuploads%2F2015%2F05%2F26%2F20430804665564348adc669.png',
    };
  }
  static navigationOptions = {
      tabBarLabel: '资讯',
      tabBarIcon: ({focused}) => {
          if (focused) {
              return (
                  <Image style={[styles.bnavImg,{width:22,height:22}]} source={require('./images/zixun1.png')}/>
              );
          }
          return (
              <Image style={[styles.bnavImg,{width:22,height:22}]} source={require('./images/zixun.png')}/>
          );
      },
  };
  isIphoneX() {

    return (

        Platform.OS === 'ios' && 

        ((SCREEN_HEIGHT === X_HEIGHT && SCREEN_WIDTH === X_WIDTH) || 

        (SCREEN_HEIGHT === X_WIDTH && SCREEN_WIDTH === X_HEIGHT))

    )

}


  ifIphoneX () {
    var flag = this.isIphoneX();
    if (flag) {
  console.log('true')
        this.setState({
          iphonex:true
        })
    } else {
  console.log('false')
        this.setState({
          iphonex:false
        })
    }
  }


  login(){
    var _this = this;
    Common.ajaxPost(Common.url + 'login.php', function(res){
      if(res.code == "0000"){

      }
    }.bind(this), {verify:'08login',t:''});
  }

  toRegister(){
    this.props.navigation.navigate('Register')
  }
  toHome(){

    this.props.navigation.goBack()
  }
  changeTabs(str){
    this.setState({
      str:str
    })
  }

  componentWillMount(){
    this.ifIphoneX();
    // console.log(this.props.navigation.state.params)
    // if(this.props.navigation.state.params.from){
    //   this.setState({
    //     from:this.props.navigation.state.params,
    //   })
    // }
  }
  render() {
    return (
      <View style={styles.container}>
        <View style={styles.head}>
          <TouchableOpacity style={styles.toback} onPress={this.toHome.bind(this)}>
            <Text style={{fontSize:16,}}>返回</Text>
          </TouchableOpacity>
          <Text style={styles.headTitle}>发帖</Text>
          <TouchableOpacity style={styles.btnSend}>
            <Text style={{fontSize:14,color:'#fff'}}>发布</Text>
          </TouchableOpacity>
        </View>
        <View style={{padding:20,}}>
          <TextInput
            style={{minHeight:100}}
            multiline={true}
            onChangeText={(text) => this.setState({text})}
            value={this.state.text}
            placeholder='我有故事，你有酒吗...'
          />
          <View style={{paddingTop:10}}>
            <TouchableOpacity style={styles.forvideo}>
              <Image style={{width:29,height:17}} source={require('./images/shipin.png')} />
            </TouchableOpacity>
          </View>

        </View>


        <View style={{height:51}}></View>
        <View style={styles.bnav}>
          <TouchableOpacity activeOpacity={1} style={styles.bnavItem} onPress={this.toHome.bind(this)}>
            <Image style={[styles.bnavImg,{width:25,height:20}]} source={require('./images/cheyuan.png')} />
            <Text style={styles.bnavText}>车源</Text>
          </TouchableOpacity>
          <TouchableOpacity activeOpacity={1} style={styles.bnavItem}>
            <Image style={[styles.bnavImg,{width:22,height:22}]} source={require('./images/zixun.png')} />
            <Text style={styles.bnavText}>资讯</Text>
          </TouchableOpacity>
          <TouchableOpacity activeOpacity={1} style={styles.bnavItem}>
            <Image style={[styles.bnavImg,{width:22,height:22}]} source={require('./images/hudong.png')} />
            <Text style={styles.bnavText}>互动</Text>
          </TouchableOpacity>
          <TouchableOpacity activeOpacity={1} style={styles.bnavItem}>
            <Image style={[styles.bnavImg,{width:22,height:22}]} source={require('./images/wode.png')} />
            <Text style={styles.bnavText}>我的</Text>
          </TouchableOpacity>
        </View>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    height:Common.screenHeight,
    backgroundColor: '#fff',
  },
  head:{
    height:50,
    width:Common.screenWidth,
    flexDirection:'row',
    alignItems:'center',
    justifyContent:'center',
    backgroundColor:'#fff',
    borderBottomColor:'#dbdbdb',
    borderBottomWidth:1,
  },
  headTitle:{
    fontSize:16,
  },
  toback:{
    flexDirection:'row',
    alignItems:'center',
    justifyContent:'center',
    height:50,
    position:'absolute',
    left:20,
    top:0,
    fontSize:14,
  },
  btnSend:{
    flexDirection:'row',
    alignItems:'center',
    justifyContent:'center',
    width:60,
    height:25,
    position:'absolute',
    right:20,
    top:12,
    backgroundColor:'#3c78ff',
    borderRadius:4,
  },
  forvideo:{
    width:82,
    height:82,
    backgroundColor:'#f5f5f5',
    flexDirection:'row',
    justifyContent:'center',
    alignItems:'center'
  },
  bnav:{
    width:Common.screenWidth,
    height:50,
    position:'absolute',
    left:0,
    bottom:0,
    flexDirection:'row',
    alignItems:'center',
    justifyContent:'center',
    backgroundColor:'#f4f5f8',
    borderTopColor:'#afafaf',
    borderTopWidth:1,
  },
  bnavItem:{
    flex:1,
    flexDirection:'column',
    alignItems:'center',
    justifyContent:'center'
  },
  bnavText:{
    textAlign:'center',
    paddingTop:5,
  },
  bnavImg:{
    margin:'auto'
  }
});
